﻿Imports BingMaps.BingMaps.BingMap
Imports System.Drawing

Public Class WebForm1
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' get the name of the control causing the postback
        Dim controlName As String = Request.Params.Get("__EVENTTARGET")
        Dim controlarguement As String = Request.Params.Get("__EVENTARGUMENT")

        If IsPostBack Then
        Else
            BingMap1.UseBingTheme = True
            'BingMap1.CustomizeOverlays = False
            BingMap1.ShowTraffic = False
            BingMap1.ShowCopyright = False
            BingMap1.DisableTouchInput = False
            BingMap1.BingMapKey = "ApFk_7cyZ93bw3SCu7SQNyvC3kOMe7rFlEgrdklxXj2DYx_m4K5KsqroNEMllv9I"
            BingMap1.Width = "800px"
            BingMap1.Height = "500px"
            BingMaps.BingMaps.BingMap.UseNewLine = True
            BingMap1.MapType = MapTypeIDEnum.Birdseye
            ' book examples
            'BingMap1.AddPushPin("ppA", 47.592, -122.332)
            'BingMap1.CenterAndZoom(47.592, -122.332, 5)

            ' add a pushpin later
            Dim nLayer As Layer = BingMap1.AddLayer("nLayer1", LayerType.Pushpin, True, 0)
            ' add points to the layer
            nLayer.AddPushpin("UW02", -31.57733, 28.76526)
            nLayer.AddPushpin("UW03", -31.55852, 28.79329)
            nLayer.AddPushpin("UW04", -31.56245, 28.80069)
            nLayer.AddPushpin("FW01", -31.57805, 28.76532)
            nLayer.AddPushpin("FW02", -31.98678, 28.13765)
            nLayer.AddPushpin("FW03", -31.81802, 28.76346)

            ' add a polyline layer
            Dim lLayer As Layer = BingMap1.AddLayer("lLayer", LayerType.Polyline, True, 0)
            Dim lPolyline As New Polyline
            lPolyline.StrokeColor = System.Drawing.Color.Red
            lPolyline.StrokeThickness = 3
            lPolyline.ZoomToPoints = True
            lPolyline.StrokeDashArray = "3 2 1 0"
            lPolyline.AddPoint(-31.71731, 28.71318)
            lPolyline.AddPoint(-31.95105, 28.54395)
            lPolyline.AddPoint(-31.61516, 28.80787)
            lPolyline.AddPoint(-31.54545, 28.19661)
            lPolyline.AddPoint(-31.57431, 28.67096)
            lPolyline.AddPoint(-31.41952, 28.86795)
            lPolyline.AddPoint(-31.63885, 28.85519)
            lPolyline.AddPoint(-31.61302, 28.9314)
            lPolyline.AddPoint(-31.95128, 28.54386)
            lPolyline.AddPoint(-31.56125, 28.22967)
            lPolyline.AddPoint(-31.12611, 28.88759)
            lPolyline.AddPoint(-31.13841, 28.31718)
            lPolyline.AddPoint(-31.21031, 28.5624)
            lPolyline.AddPoint(-31.85725, 28.55175)

            'lPolyline.StrokeColor = "100,100,0,100"
            lPolyline.ID = "KimmoPolyline"
            lLayer.AddPolyline(lPolyline)


            ' add a polygon layer
            Dim pLayer As Layer = BingMap1.AddLayer("pLayer", LayerType.Polygon, True, 0)
            ' add polygon
            Dim myPolygon As New Polygon
            myPolygon.FillColor = Color.BlueViolet
            myPolygon.StrokeColor = Color.BlueViolet
            'myPolygon.ZoomToPoints = True
            myPolygon.AddPoint(20, -20)
            myPolygon.AddPoint(20, 20)
            myPolygon.AddPoint(-20, 20)
            myPolygon.AddPoint(-20, -20)
            myPolygon.AddPoint(-20, -20)
            myPolygon.ID = "KimmoPolygon"
            pLayer.AddPolygon(myPolygon)

            'Dim oLayer As Layer = BingMap1.AddLayer("oLayer", LayerType.Pushpin, True, 0)
            'oLayer.AddPushpin("x1", 20, -20)
            'oLayer.AddPushpin("x2", 20, 20)
            'oLayer.AddPushpin("x3", -20, 20)
            'oLayer.AddPushpin("x4", -20, -20)
            'oLayer.AddPushpin("x5", -20, -20)

            'BingMap1.AddPolygon(myPolygon)
            'BingMap1.CenterAndZoom(20, -20, 3)


            ' change the color, for some reason this get put at the
            ' beginning of the map declarition *bug*
            'BingMap1.PolygonChangeColor("KimmoPolygon", "green", "green")


            'BingMap1.AddBounds(47.618594, -122.347618)
            'BingMap1.AddBounds(47.6207, -122.347584)
            'BingMap1.AddBounds(47.622052, -122.345869)

            'BingMap1.Latitude = 45.5
            'BingMap1.Longitude = -122.5

            ' example points

            ' my examples
            'visible and show on click only
            Dim aPP As New PushPin("aPP", -31.62771, 28.72805)
            'aPP.IconURL = "images/green.gif"
            aPP.AddOnClickInforBox("Project", "Upgrading of Sidwadwa substation")
            aPP.SetToolTip("Click the pushpin to see the details.")
            nLayer.AddPushpin(aPP)
            ' show tooltip
            Dim nPP As New PushPin("ppC", -31.57692, 28.76434)
            nPP.SetText("Upgrading of Thornhill station")
            nPP.TextOffset = "10,10"
            nPP.SetToolTip("Upgrading of Thornhill station")
            nPP.TypeName = "pushpinStyle"
            nPP.MoveTo = True
            nLayer.AddPushpin(nPP)

            ' mouseover
            Dim aXX As New PushPin("aBB", -31.7, 28.73)
            aXX.AddOnHoverInforBox("Project", "Upgrading of Sidwadwa substation")
            nLayer.AddPushpin(aXX)

            ' custom icon
            Dim aYY As New PushPin("aPP", -31.64771, 28.75805)
            aYY.IconURL = "images/amber.gif"
            ' this is experimental
            aYY.HoverIconURL = "images/green.gif"
            aYY.AddOnClickInforBox("Project", "Testing custom icon creation and hover icon")
            aYY.SetToolTip("Click the pushpin to see the details.")
            nLayer.AddPushpin(aYY)

            ' show user current position
            'BingMap1.ShowCurrentPosition = True

            ' these have been moved to the map new event, this is how you can
            ' add javascript to the map
            'BingMap1.AddScript("removePin", "e", _
            '                   "var indexOfPinToRemove = <map>.entities.indexOf(e.target);", _
            '                   "<map>.entities.removeAt(indexOfPinToRemove);")
            '
            'BingMap1.AddScript("hideAllEntities", "", "<map>.entities.setOptions({visible:false});")
            'BingMap1.AddScript("showAllEntities", "", "<map>.entities.setOptions({visible:true});")
            'BingMap1.AddScript("SetZoom", "e", "<map>.setView({zoom:e});")
            'BingMap1.AddScript("SetCenter", "lat,lng", _
            '                   "var <map>_Center = new Microsoft.Maps.Location(lat,lng);", _
            '                   "<map>.setView({center: <map>_Center});")

            'BingMap1.AddScript("GetCenter", "return <map>.GetCenter;")
            'BingMap1.AddScript("GetMapEntity", "id", "return <map>.entities.get(id);")

            'BingMap1.AddScript("addPin", "e", _
            '                   "if (e.targetType == ""<map>"")",
            '                   "{", _
            '                    "var map_point = new Microsoft.Maps.Point(e.getX(), e.getY());", _
            '                    "var map_loc = e.target.tryPixelToLocation(map_point);", _
            '                    "var map_pin = new Microsoft.Maps.Pushpin(map_loc);", _
            '                    "<map>.entities.push(map_pin);",
            '                    "}")


            'BingMap1.AddPinAtClickPosition = True
            ' print the map
            'BingMap1.Print = True


        End If
    End Sub

    Private Sub btnPrint_Click(sender As Object, e As EventArgs) Handles btnPrint.Click
        ' execute script
        'Dim result As Object = Me.Browser.InvokeScript("BingMap1.printMap", False)
    End Sub


End Class